package com.wxq.yaoxia.mainborad;

import com.wxq.yaoxia.R;
import com.wxq.yaoxia.YXAboutActivity;
import com.wxq.yaoxia.YXBaseActivity;
import com.wxq.yaoxia.YXHelpActivity;
import com.wxq.yaoxia.YXLoginActivity;
import com.wxq.yaoxia.YXRegisterActivity;
import com.wxq.yaoxia.YXUpdateActivity;
import com.wxq.yaoxia.disease.YXDiseaseSearchActivity;
import com.wxq.yaoxia.drug.YXDurgSearchActivity;
import com.wxq.yaoxia.util.YXConstants;

import android.app.SearchManager;
import android.app.SearchManager.OnDismissListener;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class YXMainboradActivity extends YXBaseActivity {

	ImageButton searchBar;
	
	Button mbButton1;
	Button mbButton2;
	Button mbButton3;
	Button mbButton4;
	private Button mbButton5;
	private Button mbButton6;
	private Button mbButton7;
	private Button mbButton8;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentViewWithTopbar(R.layout.yx_mainborad, R.layout.yx_topbar_search);
		
		searchBar = (ImageButton) findViewById(R.id.searchBar);
		searchBar.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				onSearchRequested();
			}
		});
		
		mbButton1 = (Button) findViewById(R.id.mainboradBtn1);
		mbButton1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXDurgSearchActivity.class);
				intent.putExtra(YXConstants.YX_USE, YXConstants.YX_USE_DRUG);
				YXMainboradActivity.this.startActivity(intent);
//				TabActivity activity;
			}
		});
		
		mbButton2 = (Button) findViewById(R.id.mainboradBtn2);
		mbButton2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXDiseaseSearchActivity.class);
				intent.putExtra(YXConstants.YX_USE, YXConstants.YX_USE_DISEASE);
				YXMainboradActivity.this.startActivity(intent);
				
			}
		});
		
		mbButton3 = (Button) findViewById(R.id.mainboradBtn3);
		mbButton3.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXLoginActivity.class);
				YXMainboradActivity.this.startActivity(intent);
				
			}
		});
		
		mbButton4 = (Button) findViewById(R.id.mainboradBtn4);
		mbButton4.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXRegisterActivity.class);
				YXMainboradActivity.this.startActivity(intent);
				
			}
		});
		
		mbButton5 = (Button) findViewById(R.id.mainboradBtn5);
		mbButton5.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXHelpActivity.class);
				YXMainboradActivity.this.startActivity(intent);
				
			}
		});
		
		mbButton6 = (Button) findViewById(R.id.mainboradBtn6);
		mbButton6.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXUpdateActivity.class);
				YXMainboradActivity.this.startActivity(intent);
				
			}
		});
		
		mbButton7 = (Button) findViewById(R.id.mainboradBtn7);
		mbButton7.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				sendMailByIntent();
				
			}
		});
		
		mbButton8 = (Button) findViewById(R.id.mainboradBtn8);
		mbButton8.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(YXMainboradActivity.this, YXAboutActivity.class);
				YXMainboradActivity.this.startActivity(intent);				
			}
		});
	}

	@Override
	public void setTopBarButtonListener() {
		// TODO Auto-generated method stub
		Button leftBtn = (Button) findViewById(R.id.btnLeft);
    	Button rightBtnButton = (Button) findViewById(R.id.btnRight);
    	
    	leftBtn.setVisibility(View.INVISIBLE);
    	rightBtnButton.setVisibility(View.INVISIBLE);
	}
	
	public int sendMailByIntent() {  
        String[] reciver = new String[] { "mobile@yaoxia.com" };  
        String[] mySbuject = new String[] { "反馈给药侠" };  
        String myCc = "";
        String mybody = "请输入反馈给药侠的信息";  
        Intent myIntent = new Intent(android.content.Intent.ACTION_SEND);  
        myIntent.setType("plain/text");  
        myIntent.putExtra(android.content.Intent.EXTRA_EMAIL, reciver);  
        myIntent.putExtra(android.content.Intent.EXTRA_CC, myCc);  
        myIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySbuject);  
        myIntent.putExtra(android.content.Intent.EXTRA_TEXT, mybody);  
        startActivity(Intent.createChooser(myIntent, "mail"));  
  
        return 1;  
    }
	
	public boolean onSearchRequested() {
		
		
		((View) findViewById(R.id.list_search_overlay)).setVisibility(View.VISIBLE);
		 final SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);
		 searchManager.setOnDismissListener(new OnDismissListener() {

			 @Override
			 public void onDismiss() 
			 {
				 ((View)findViewById(R.id.list_search_overlay)).setVisibility(View.GONE);
				 searchBar.setVisibility(View.VISIBLE);
			 }
		});
		 
		searchBar.setVisibility(View.GONE);

		Bundle appDataBundle = new Bundle();
		appDataBundle.putString("demo_key", "dddd");

		startSearch("", true, appDataBundle, false);
		return true;
	}

}
